package com.kool.kadmin.system.vo;

import com.kool.kadmin.system.bean.SysParamDo;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * @author luyu
 */
@Data
@Accessors(chain = true)
public class ParamVo {
    /**
     * 参数码
     */
    @NotBlank(message = "参数码不能为空")
    private String paramCode;
    /**
     * 参数名
     */
    @NotBlank(message = "参数名不能为空")
    private String paramName;
    /**
     * 键
     */
    private String paramKey;
    /**
     * 值
     */
    private String paramValue;
    /**
     * 父参数码
     */
    private String fatherCode;
    /**
     * 根参数码
     */
    @NotBlank(message = "根参数码不能为空")
    private String rootCode;
    /**
     * 深度，从0开始
     */
    @NotNull(message = "深度不能为空")
    @Min(value = 0L,message = "深度从0开始")
    private Integer deep;

    /**
     * 数据转换
     *
     * @param sysParamDo
     * @return
     */
    public static ParamVo parse(SysParamDo sysParamDo) {
        if (sysParamDo == null) {
            return null;
        }
        ParamVo paramVo = new ParamVo();
        paramVo.setParamCode(sysParamDo.getParamCode())
                .setParamName(sysParamDo.getParamName())
                .setParamKey(sysParamDo.getParamKey())
                .setParamValue(sysParamDo.getParamValue())
                .setFatherCode(sysParamDo.getFatherCode())
                .setRootCode(sysParamDo.getRootCode())
                .setDeep(sysParamDo.getDeep());
        return paramVo;
    }
}
